package com.sale.system.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.SysDown;
import com.sale.system.domain.SysStaffManagement;
import com.sale.system.service.ISysStaffManagementService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;


/**
 * @Author: YSL
 * @Date: 2023-07-05 17:22:26
 * @Desc: 职员管理Controller
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/staffManagement")
public class SysStaffManagementController extends BaseController {

    /**
     * 职员管理Service
     */
    private final ISysStaffManagementService sysStaffManagementService;


    /**
     * 分页获取账户管理列表
     * @param sysStaffManagement
     * @param pageQuery
     * @return
     */
    //@SaCheckPermission("system:clerk:list")
    @GetMapping("/list")
    public TableDataInfo<SysStaffManagement> list(SysStaffManagement sysStaffManagement, PageQuery pageQuery) {
        return sysStaffManagementService.selectStaffManagementList(sysStaffManagement, pageQuery);
    }

    /**
     * 根据id查询账户管理详情
     *
     * @param staffId 职员管理ID
     */
    //@SaCheckPermission("system:clerk:query")
    @GetMapping(value = "/{staffId}")
    public R<SysStaffManagement> getInfo(@PathVariable Long staffId) {
        return R.ok(sysStaffManagementService.getStaffManagementById(staffId));
    }

    /**
     * 新增职员管理
     * @param sysStaffManagement
     * @return
     */
    //@SaCheckPermission("system:clerk:add")
    @Log(title = "职员管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody SysStaffManagement sysStaffManagement) {
        return toAjax(sysStaffManagementService.insertStaffManagement(sysStaffManagement));
    }

    /**
     * 修改职员管理
     * @param sysStaffManagement
     * @return
     */
    //@SaCheckPermission("system:clerk:edit")
    @Log(title = "职员管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody SysStaffManagement sysStaffManagement) {
        return toAjax(sysStaffManagementService.updateStaffManagement(sysStaffManagement));
    }

    /**
     * 删除职员管理
     *
     * @param staffId 职员管理ID
     */
    //@SaCheckPermission("system:clerk:remove")
    @Log(title = "职员管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{staffId}")
    public R<Void> remove(@PathVariable Long staffId) {
        return toAjax(sysStaffManagementService.deleteStaffManagement(staffId));
    }

    /**
     * 删除职员管理
     *
     * @param staffId 员管理ID串
     */
    //@SaCheckPermission("system:clerk:remove")
    @Log(title = "职员管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/removeList/{staffId}")
    public R<Void> remove(@PathVariable Long[] staffId) {
        return toAjax(sysStaffManagementService.deleteStaffManagementList(staffId));
    }

    /**
     * 职员管理列表（不分页）
     */
    @GetMapping("/downList")
    public R<List<SysDown>> downList() {
        return R.ok(sysStaffManagementService.downList());
    }
}
